<?php include './application/views/common/zhs_header.php';?>
<?php include './application/views/common/zhs_usercenter_acnt.php';?>
<div class="inv_box w">
<?php include './application/views/common/zhs_usercenter_left.php';?>
  <div class="membd_right">
     <h3 class="membdrg_tit">邮箱认证</h3>
    <div class="mem_perbox">
    	<form id="email_form">
    	<ul>
<?php if($user['email_status'] == 1){ ?>
		<li>您的邮箱已经通过认证：<?php echo strdisplay($user['email'],0); ?>
		<a href="javascript:;" onclick="huanblock();"  style="color: #a71e32; text-decoration:underline;padding-left:120px;">绑定更换</a>
		</li>
		<div id="emailhuan" style="display:none">
			<div class="user_right_border">
					<div class="emab"><span style="float:left">更换条件：</span>
					<input style="float:left; margin:0 4px;" type="radio" name="typer" value="oldemail" onclick="typeremail(this);" checked ><span style="float:left">旧邮箱更换</span>
					<input style="float:left; margin:0 4px;" type="radio" name="typer" value="phone" onclick="typeremail(this);" ><span style="float:left">手机更换</span>
					</div>
				
			</div>
			<div id="oldemail" style="display:block">
				<div class="user_right_border">
					<div class="l">旧邮箱验证码：</div>
					<div class="c">
						<input type="text" value="" name="old_verify_code" maxlength="20">
						<span id="old_code">
						<input type="button" value="获取验证码" onclick="emaiSmit('apply');">
						</span>
					</div>
				</div>
				
			</div>
			
			<div id="phone" style="display:none">
				<div class="user_right_border">
					<div class="l">手机验证码：</div>
					<div class="c">
						<input type="text" value="" name="verify_code" maxlength="12">
						<span id="phone_code">
							<input type="button" value="获取验证码" onclick="peSubmit();">
						</span>
					</div>
				</div>
			</div>
			<div class="user_right_border">
				<div class="l">新邮箱：</div>
				<div class="c">
					<input type="text" value="" name="emai" id="emai" maxlength="28">
				</div>
			</div>
			<input type="button"  class="little_button"  size="30" value="确认提交" onclick="emailSubmit('submit')">
		</div>
<?php } else {?>
		<li><span style="float:left;"><em style="float:left;">邮箱：</em><input style="padding-top:6px; float:left; height:22px; padding-left:6px;" type="text" value="<?php echo isset($user['email']) ? $user['email'] : ''; ?>" name="emai" id="emai"> </span><input style="float:left; margin-top:2px;" type="button"  class="little_button"  size="30" value="确认提交" onclick="emailSubmit('submit')"></li>
		<li></li>
<?php }?>
    	</ul>
    	</form>
     </div>
<script  type="text/javascript">
function huanblock(){
	var submenu=document.getElementById('emailhuan');
	
	submenu.style.display="block";
}
function typeremail(obj){
	var oldemail=document.getElementById('oldemail');
	var phone=document.getElementById('phone');
	if(obj.value == 'oldemail') {
		oldemail.style.display = 'block';
		phone.style.display = 'none';
	}
	else if(obj.value  == 'phone'){
		oldemail.style.display = 'none';
		phone.style.display = 'block';
	}
}

<?php if(isset($msg) && $msg!=''){?>
$(function(){
	$('#dialog').dialog({
		modal:true,
		title:'系统提示',
		buttons:{"确定":function(){$(this).dialog("close");}},
		close: function() {
			location="/user/zhs_center";
		}
	}); 
	$("#msg").html("<?php echo $msg;?>");
});

<?php }?>


function emailSubmit(teru){
	var options = {
		url : GetUrlRelativePath(),
		beforeSubmit:  checkForm,
		dataType: "json",
		type:"post",
		data: {"act":teru}, 
		success : function(ret) {
			if(ret.msg==''){
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");window.location="/user/zhs_user_safe.html";}}
				}); 
				$("#msg").html(ret.cont);
				
			}else{
				$('#dialog').dialog({
					modal:true,
					title:'系统提示',
					buttons:{"确定":function(){$(this).dialog("close");}}
				}); 
				$("#msg").html(ret.msg);
			}
		}
	};
	$("#email_form").ajaxSubmit(options);
	return false;
}

function checkForm(){
	var err = '';
	if($('#emai').val()==''){
		err = '请填写邮箱';
	}else if(IsEmail($('#emai').val())==false){
		err = '请填写有效邮箱';
	}
	if(err==''){
		return true;
	}else{
		$('#dialog').dialog({
			modal:true, //蒙层（弹出会影响页面大小）
			title:'系统提示',
			buttons:{"确定":function(){$(this).dialog("close");}}
		}); 
		$("#msg").html(err);
		return false;
	}
}
function emaiSmit(teru){
	$.ajax({
		type: "post",
		url: "/user/zhs_email.html",
		data: {"act":teru}, 
		success: function(ret){
			if(ret.info == 1){
				$("#old_code").html("邮箱验证码已发送,请查收");
			}else{
				$("#old_code").html(ret.msg);
				setTimeout(function(){
				$("#old_code").html('<a href="javascript:;" onclick="emaiSmit();" style="color:#a71e32; text-decoration:underline"> 重新获取邮箱验证码</a>');
					
				},10000);
			}
		},
		dataType: "json"
	});	
}
function peSubmit(){
	$("#phone_code").html('处理中，请等待');
	$.ajax({
		type: "post",
		url: "/reg/sendsms.html",
		success: function(ret){
			if(ret.info == 1){
				phone_countdown();
			}else{
				$("#phone_code").html(ret.msg);
				setTimeout(function(){
				$("#phone_code").html('<a href="javascript:;" onclick="peSubmit();" style="color:#a71e32; text-decoration:underline"> 重新获取手机验证码</a>');
					
				},3000);
			}
		},
		dataType: "json"
	});	
}
function phone_countdown(){
	var count = 180;
	var countdown = setInterval(CountDown, 1000); 
	function CountDown() {
		$("#phone_code").html('手机验证码已发送,请等待 <font style="color:#a71e32;">'+count+"</font>秒");
		if (count == 0) {
			$("#phone_code").html('<a href="javascript:;" onclick="peSubmit();" style="color:#a71e32; text-decoration:underline"> 重新获取手机验证码</a>');
			clearInterval(countdown);
		}
		count--;
	}
}

</script>
   </div>
</div> 

<?php include './application/views/common/zhs_footer.php';?>
<?php include './application/views/common/zhs_right.php';?>
    
